package ua.org.extjsbuilder.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;

import ua.org.extjsbuilder.wizards.CSSNewFileWizard;

public class NewCSSFileAction implements IViewActionDelegate {
	private Shell shell;
	private IStructuredSelection selection;
	
	public NewCSSFileAction() {
		super();
	}

	public void run(IAction action) {
		CSSNewFileWizard wizard = new CSSNewFileWizard();
		wizard.init(null, selection);
		WizardDialog newComponentWizard = new WizardDialog(shell, wizard);
		newComponentWizard.open();
	}

	public void selectionChanged(IAction action, ISelection selection) {
		setSelection(selection);
	}

	public void init(IViewPart view) {
		setSelection(view.getSite().getSelectionProvider().getSelection());
		this.shell = view.getSite().getShell();
	}
	
	private void setSelection(ISelection selection){
		if(selection instanceof IStructuredSelection){
			this.selection = (IStructuredSelection)selection;
		}
	}
}
